// const currentImageIndex=1
const App=getApp()
const maxlength=0
const getCurrentDate = require('../../utils/util')
const httpRequest=require('../../utils/httpRequest.js')

Page({
  data: {
    showingList:{},
    cinemas:{},
    currentImageIndex:1,
    currentDate: '',
    tickets: {},
    maxlength,
    Token:''
  },

  onLoad: function(options) {
    const userToken = wx.getStorageSync('userToken'); 
    this.setData({
      currentDate: getCurrentDate.getCurrentDate(),
      Token:userToken
    });
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('acceptDataFromCmaPage', (data) => {
      this.setData({
        cinemas: data.data
      });
      
      //获取影院的电影
      const cid = this.data.cinemas.id;
      httpRequest.Request('Post',App.globalData.backend_add+"api/bookings/getMovieById?id="+cid,{},{'Authorization': this.data.Token ,'content-type': 'application/json'},'showingList','maxlength',this)
    });
  },

  //切换电影
  onSwiperChange(e) {
    const cid = this.data.cinemas.id;
    const current = e.detail.current;
    const length=this.data.maxlength;
    this.setData({
      currentImageIndex:(current+1)%length,
    });
    const index=this.data.showingList[this.data.currentImageIndex].id;
    const data={
      cid: cid,
      mid: index
    };

    //获取该影院该电影的场次信息
    httpRequest.Request('Post',App.globalData.backend_add+"api/bookings/getBookingByCidAndMid?cid="+data.cid+"&mid="+data.mid,{},{'Authorization': this.data.Token ,'content-type': 'application/json'},'tickets','null',this)
  },
})
  


